@extends('admin.layouts.app')

@section('right-content')
    <fieldset class="layui-elem-field layui-field-title">
        <legend>
        <span class="layui-breadcrumb">
            <a href="javascript:;">玩家管理</a>
            <a><cite>{{ $title }}</cite></a>
        </span>
        </legend>
    </fieldset>

    <table id="dateTable" class="layui-table">
        <thead>
        <tr>
            <th><input type="checkbox" class="my-checkbox" /></th>
            <th>玩家ID</th>
            <th>玩家昵称</th>
            <th>性别</th>
            <th>注册渠道</th>
            <th>登录次数</th>
            <th>最后登录时间</th>
            <th>最后登录IP</th>
            {{-- <th>最后登录地址</th> --}}
            <th>状态</th>
            <th>冻结原因</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @foreach($gamers as $gamer)
            <tr>
                <td><input type="checkbox" class="my-checkbox" data-id="{{ $gamer->id }}" /></td>
                <td><a href="{{ route('gamers.show', ['id' => $gamer->id]) }}">{{ $gamer->id }}</a></td>
                <td>{{ $gamer->nickname }}</td>
                <td>@if ($gamer->male == 1) 男 @else 女 @endif</td>
                <td>{{ $gamer->channel }}</td>
                <td>{{ $gamer->login_times }}</td>
                <td>{{ $gamer->login_time_lately }}</td>
                <td>{{ $gamer->login_ip }}</td>
                {{-- <td>{{ $gamer['male'] }}</td> --}}
                <td>@if($gamer->status == 1) 正常 @elseif($gamer->status == 2) 禁言 @else 冻结 @endif</td>
                <td>{{ $gamer->freeze_reason }}</td>
                <td>
                    @if ($gamer['status'] == 1)
                        <button class="layui-btn layui-btn-small layui-btn-normal pushBlackList" data-url="{{ route('gamers.pushBlackList', ['id' => $gamer->id]) }}">加入黑名单</button>
                    @elseif ($gamer['status'] == 3)
                        <button class="layui-btn layui-btn-small layui-btn-warm popBlackList" data-url="{{ route('gamers.popBlackList', ['id' => $gamer->id]) }}">移出黑名单</button>
                    @endif
                    {{-- <button class="layui-btn layui-btn-small layui-btn-danger delete" data-url="{{ route('gamers.destroy', ['id' => $gamer->id]) }}">删除</button> --}}
                </td>
            </tr>
        @endforeach
        </tbody>
    </table>


@endsection

@section('my-js')
{{-- <script type="text/javascript" src="http://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script> --}}
{{-- <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/fixedheader/3.1.3/css/fixedHeader.dataTables.min.css"> --}}
{{-- <script type="text/javascript" src="https://cdn.datatables.net/fixedheader/3.1.3/js/dataTables.fixedHeader.min.js"></script> --}}
{{-- <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.15/css/jquery.dataTables.css"> --}}
<script type="text/javascript" src="{{ asset('admin/js/jquery.dataTables.min.js') }}"></script>{{-- 1.10.16 --}}
<script type="text/javascript" src="{{ asset('admin/js/table-tool.js') }}"></script>
<script type="text/javascript">
    layui.use(['layer', 'form'], function() {
        var $ = layui.jquery,element = layui.element,layer = layui.layer;

        // 初始化表格
        $('#dateTable').DataTable({
            "dom": '<"top"f>rt<"bottom"lp><"clear">',
            "autoWidth": false,                     // 自适应宽度
            "stateSave": true,                      // 刷新后保存页数
            'ordering':false,
            // "order": [[ 1, "desc" ]],               // 排序
            "searching": true,                     // 本地搜索
            "processing": true,                     // 显示加载过程
            "info": true,                           // 控制是否显示表格左下角的信息
            "stripeClasses": ["odd", "even"],       // 为奇偶行加上样式，兼容不支持CSS伪类的场合
            "columnDefs": [{                      // 指定列不参与排序
                "orderable": false,
                "targets": [0,2,3,6,7,8,9]                   // 对应你的表格的列数
            }],
            "pagingType": "simple_numbers",         // 分页样式 simple,simple_numbers,full,full_numbers
            "language": {                           // 国际化
                "url":"{{ asset('admin/language.json') }}"
            },
            fixedHeader: true,                      //头部固定
            // initComplete: function() {
            //     $('.top').append('<span class="fl"><a class="layui-btn layui-btn-danger radius btn-delect" id="btn-delete-all">批量删除</a></span>');
            // },

        });

        // 例:获取ids
        $(document).on('click','#btn-delete-all', function(){
            // getIds(table对象,获取input为id的属性)
            var list = getIds($('#dateTable'),'data-id');
            if(list == null || list == ''){
                layer.msg('未选择');
            }else{
                // layer.msg(list);
                layer.confirm('is not?', {icon: 3, title:'提示', content:'您确定要删除吗？'}, function(index){
                    layer.close(index);
                    $.post("{{ route('gamers.destroyList') }}", {ids : list}, function(data) {
                        console.log(data);
                        if (data.status == 0) {
                            top.layer.msg(data.msg, {icon: 1, time: 2000});
                            window.location.href = data.url;
                        } else {
                            top.layer.msg(data.msg, {icon: 2, time: 2000});
                            window.location.reload();
                        }
                    },'json');
                });
            }
        });

        $(document).on('click','.edit', function(){
            var url = $(this).attr('data-url');
            window.location.href = url;
        });

        $(document).on('click','.delete', function(){
            var url = $(this).attr('data-url');
            commonAjaxRequest(url, 'DELETE')
        });

        //加入黑名单
        $(document).on('click','.pushBlackList', function(){
            var url = $(this).attr('data-url');
            layer.open({
              type: 1,
              title: '填写原因',
              skin: 'layui-layer-rim', //加上边框
              area: ['420px', '240px'], //宽高
              content: '<form class="layui-form" id="blacklist">{{ csrf_field() }}<textarea name="desc" placeholder="请输入内容" lay-verify="required" class="layui-textarea"></textarea><div class="layui-form-item"><div class="layui-input-block"><button class="layui-btn" lay-submit lay-filter="sub" data-url="'+url+'">立即提交</button><button type="reset" class="layui-btn layui-btn-primary">重置</button></div></div></form>'
            });

            // commonAjaxRequest(url, 'PUT')
        });

        layui.form.on('submit(sub)', function(data){
            var url = $(this).attr('data-url');
            commonAjaxSubmit(url, 'POST', '#blacklist');

        });

        //移出黑名单
        $(document).on('click','.popBlackList', function(){
            var url = $(this).attr('data-url');
            commonAjaxRequest(url, 'PUT')
        });

    })

</script>
@endsection






